#ifndef CURVECTRL_H
#define CURVECTRL_H

#include <QMouseEvent>
#include <QPainter>

#include "dm/dmstruct.h"
#include "dm/filter.h"


// 移动方向枚举
enum class MoveDirection : uint16_t
{
    Free,       // 自由移动
    Horizontal, // 仅横向移动
    Vertical,   // 仅纵向移动
    Disabled    // 不可移动
};

struct CtrlButton
{
    bool dragging;
    bool show;
    MoveDirection direction;
    QRectF rect;
};

class CtrlButtonGroup
{
public:
    CtrlButtonGroup();
    CtrlButtonGroup(const double &ratio, const DMVariant &dm, const QString &text);
    void setDm(const DMVariant &dm);
    void draw(QPainter &painter, const QSize &size);
    void showFG(bool show);
    void showLRQ(bool show);
    void setFGDirection(MoveDirection direction);
    void setSelect(const QPoint &point);
    void dragCancel();
    void deselect();
    DMVariant newDm(const QPoint &point, const QSize &size) const;
    bool dragging() const;
    bool contains(const QPoint &point) const;
    bool containsFG(const QPoint &point) const;
    bool containsLQ(const QPoint &point) const;
    bool containsRQ(const QPoint &point) const;
    static QPointF toPoint(const QSize &size, const double &freq, const double &gain);

    bool selected;      // 选中
    DMVariant dm;       // 参数
    PairArray array;    // gain array
    QString text;       // 文本
    CtrlButton fg;      // 频率/增益
    CtrlButton lq;      // 左 Q值
    CtrlButton rq;      // 右 Q值
    CtrlButton tbox;    // 文本框
};


#endif // CURVECTRL_H
